$PrintDebugOn =False
$Silence =0
$SendSpeechToPC =1
$SendSpeechToRobot =2
$table=0
$SendSpeechTo =$SendSpeechToPC #Default. Change as needed
DefineArray($symbol,3," ")
DefineArray($Lastis,3," ")
DefineArray($QuoteDate,3," ")
DefineArray($QuoteTime,3," ")
DefineArray($TotalChg,3," ")
DefineArray($PercentChg,3," ")
DefineArray($TheSign,3," ")
DefineArray($IndStatus,3," ")

# Enter the full path and name of the files to be used
$VZFile ="C:\users\public\documents\VZ.txt"
$ModVZFile ="C:\users\public\documents\ModVZ.txt"

# The full path and name of the HTML scrubber program.
$ScrubProg ="c:\users\public\documents\HTMLScrub.exe"
$IndexesToGet ="COMP,DJIA,SPX"

FileDelete($VZFile) #Clears the file and prevents adding to it needlessly
FileWrite($VZFile,HTTPGet("http://www.marketwatch.com/tools/marketsummary/indices/indices.asp?indexid=1&groupid=37" ))
FileReadClose($ModVZFile)
Sleep(2000)
Exec($ScrubProg) #Modifies $VZFile.txt and creates $VZModFile.txt
Sleep(3000) #May need to be adjusted depending on file size.
FileReadReset($ModVZFile)

$TheIndexesToGet =$IndexesToGet+"," #So we don't mess up the original

# $Prefix is used to get the correct line with the index name.
# This needed because the index name is used in many lines.
$Prefix ="<td class=symb-col><a href= investing index "
repeatwhile($TheIndexesToGet !="")
  $IndexPhrase =$Prefix+Split($TheIndexesToGet,",",0) #First index
  if ($PrintDebugOn)
    Print($IndexPhrase)
  endif
  FileReadReset($ModVZFile) #Always start from the beginning
  $ExitLoop =False
  repeatwhile(FileReadEnd($ModVZFile)=0 AND $ExitLoop =False)
    $TheText =FileReadLine($ModVZFile)
    $StartPos =IndexOf($TheText,$IndexPhrase)
    if ($StartPos >-1) #Found $IndexPhrase
      $StartStr ="title=" #This preceeds the full name
      $EndStr =">" #This is at the end of the full name
      $LeadinStr ="" #No Leadin Phrase needed

      Goto(ExtractVal) #Get and say the full name

      $LinesToRead =2
      Goto(ReadFileLines) #Skip a line
      $StartStr =">" #All are be bounded by these symnol,
      $EndStr ="<"   #so we only need to declare them once.
      $LeadinStr ="Last is"
      Goto(ExtractVal)

      $TheText =FileReadLine($ModVZFile)
      $LeadinStr ="The date is" #Commented out for now
      Goto(ExtractVal)

      $TheText =FileReadLine($ModVZFile)
      $LeadinStr ="The time is"
      Goto(ExtractVal)

      $TheText =FileReadLine($ModVZFile)
      $LeadinStr ="The change is"
      Goto(ExtractVal)

      $TheText =FileReadLine($ModVZFile)
      $LeadinStr ="The percent change is"
      Goto(ExtractVal)

      $ExitLoop =True #Done so exit the repeat loop
    endif
  endrepeatwhile
  $TempStr =$TheIndexesToGet #Have to do this because of bug in script language
  $StartPos =IndexOf($TheIndexesToGet,",")
  $LenStr   =Length($TheIndexesToGet)
  $TheIndexesToGet =SubString($TempStr,$StartPos+1,$LenStr-$StartPos-1) #Remove first name
  if ($PrintDebugOn)
    Print("$TheIndexesToGet ="+$TheIndexesToGet)
  endif
endrepeatwhile
Goto(TheExit)

:ReadFileLines
$NextLine =0 #This is a routine for skipping lines in the file
repeatwhile($NextLine < $LinesToRead AND FileReadEnd($ModVZFile)=0)
  $TheText =FileReadLine($ModVZFile)
  $TheText =ToString($TheText) #To help insure wrong characters are removed
  $NextLine++
endrepeatwhile
Return() #The last line read should be the line with a value.

:ExtractVal

$TheStartStr =$StartStr #Defaults
$TempStr     =$TheText
if ($PrintDebugOn)
  Print("$StartStr ="+$StartStr)
endif
$StartPos =IndexOf($StartStr,"|") #See if the $StartStr is multipart
repeatwhile($StartPos >0) #Process each phrase in $StartStr
  if ($PrintDebugOn)
    Print("*******In ExtractVal Repeat Loop***********")
  endif
  $LenStartStr =Length($StartStr)
  $TheStartStr =SubString($StartStr,0,$StartPos) #Extract first part
  $TempStartStr =$StartStr #Have to do this because of a bug in script language
  $StartStr =SubString($TempStartStr,$StartPos+1,$LenStartStr-$StartPos-1) #Get rest of $StartStr

  if ($PrintDebugOn)
    Print("$StartStr ="+$StartStr)
    Print("$TheStartStr ="+$TheStartStr)
    Print("$StartPos ="+$StartPos)
    Print("$LenStartStr ="+$LenStartStr)
  endif

  $LenStartStr =Length($TheStartStr)
  $StartPos    =IndexOf($TempStr,$TheStartStr)+$LenStartStr
  $LenStr      =Length($TempStr) #Current length of string
  $TheText     =$TempStr #Have to do this because of a bug in script language
  $TempStr     =SubString($TheText,$StartPos,$LenStr-$StartPos)

  if ($PrintDebugOn)
    Print("$TempStr ="+$TempStr)
    Print("$StartPos ="+$StartPos)
  endif

  $StartPos =IndexOf($StartStr,"|") #See if there is another part
  if ($PrintDebugOn)
    Print("$StartPos ="+$StartPos)
  endif
endrepeatwhile
$TheText =$TempStr

if ($PrintDebugOn)
  Print("$TempStr ="+$TempStr)
  Print("$LeadInStr ="+$LeadInStr)
endif
$LenStartStr =Length($TheStartStr)
$StartPos =IndexOf($TheText,$TheStartStr)+$LenStartStr #Find where the value is.
$LenStr   =Length($TheText) #Current length of string

if ($PrintDebugOn)
  Print($TheText)
  Print("$StartPos ="+$StartPos)
  Print("$LenStr ="+ $LenStr)
endif
  # Extract the characters from $StartPos to the end of string
$TempStr =SubString($TheText,$StartPos,$LenStr-$StartPos)

if ($PrintDebugOn)
  Print("$TempStr ="+$TempStr)
endif
if ($EndStr !="") #If not a blank string then there is an end string
  $EndPos =IndexOf($TempStr,$EndStr) #Find the end boundry of the data
  $TheSubString ="AA"
  $TheSubString =SubString($TempStr,0,$EndPos) #Get everything to $EndPos

  if ($PrintDebugOn)
    Print("$EndStr ="+$EndStr)
    Print("$EndPos ="+$EndPos)
  endif

ELSE #No $EndStr so we want everything to the end
  $TheSubString ="AA"
  $TheSubString =$TempStr
endif


if ($LeadinStr="")
  $symbol[$table] =$TheSubString
ELSEif ($LeadinStr="Last is")
  $LastIs[$table] = $TheSubString
ELSEif ($LeadinStr="The date is")
  $QuoteDate[$table] = $TheSubString
ELSEif ($LeadinStr="The time is")
  $QuoteTime[$table]=$TheSubString
ELSEif ($LeadinStr="The change is")
  $TotalChg[$table]=$TheSubString
ELSEif ($LeadinStr="The percent change is")
  $howlong = Length($TheSubString)
  $PercentChg[$table]=substring($TheSubString,1,$howlong-1)
  $TheSign[$table]=substring($TheSubString,0,1)
  $table=$table+1
endif

$symbol[0]=" The NASDAQ"
$symbol[1]=" The DOW"
$symbol[2]=" The S and P 500"

if ($TheSign[0] = "-")
  $IndStatus[0] =" is trading lower by "
ELSE
  $IndStatus[0] =" is trading higher by "
endif

if ($TheSign[1] = "-")
  $IndStatus[1] =" is trading lower by "
ELSE
  $IndStatus[1] =" is trading higher by "
endif

if ($TheSign[2]= "-")
  $IndStatus[2] =" is trading lower by "
ELSE
  $IndStatus[2] =" is trading higher by "
endif

if ($table=3)
  Print ("as of "+ $quotetime[0] + $symbol[0] + $IndStatus[0] + $PercentChg[0])
  Print ("as of "+ $quotetime[1] + $symbol[1] + $IndStatus[1] + $PercentChg[1])
  Print ("as of "+ $quotetime[2] + $symbol[2] + $IndStatus[2] + $PercentChg[2])
  goto (TheExit)
endif


return()




:TheExit
FileReadClose($ModVZFile) #Make sure it is closed




